home *** CD-ROM | disk | FTP | other *** search
- Path: dialup-147.austin.io.com!user
- From: hamilton@shokwave.com (Jim Hamilton)
- Newsgroups: comp.lang.c++
- Subject: Re: Q:order of evaluation
- Date: Thu, 18 Jan 1996 20:45:57 -0600
- Organization: Disorganized
- Message-ID: <hamilton-1801962045570001@dialup-147.austin.io.com>
- References: <4dfhlu$a33$1@mhafn.production.compuserve.com>
- NNTP-Posting-Host: dialup-147.austin.io.com
- X-Newsreader: Yet Another NewsWatcher 2.0.5b5
-
- In article <4dfhlu$a33$1@mhafn.production.compuserve.com>, Holger Maier
- <100336.3326@CompuServe.COM> wrote:
-
- >Consider
- >#include <iostream>
- >int main() {
- > int i=1;int j=i+(i+=1);
- > cout<<i<<','<<j<<'\n';
- > return 0;
- >}
- >on my compiler this produces 2,4
- >Looked up the ARM:
- >5: .. The order of evaluation of subexpressions is determined by the
- >precedence and grouping of operators.
- >5.7: The additive operators + and - group left to right.
- >So, j should be assigned 3 ??
- >Now the question to you C++ gurus out there on the nets:
- >Is it really a compiler bug or is it just me misinterpreting the
- >ARM?
- >BTW: I know we should not code like that...
- >Holger
-
- The highest precedence in any expression is the insides of parentheses
- (). Therefore (i+=1) is evaluated before i+().
-
- --
- JFH
-
- [This .sig intentionally left blank.]
-